GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4a2f15...db4227 )
by Florian
01:21
created

map.js ➔ repairLat   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 9
rs 9.6666
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $, google, Lines, Markers, Conversion, Cookies, Coordinates, trackMarker, mytrans, showAlert,
7
  id2alpha, alpha2id,
8
  showProjectionDialog, showLinkDialog,
9
  osmProvider, osmDeProvider, ocmProvider, thunderforestOutdoorsProvider, opentopomapProvider,
10
  get_cookie_int, get_cookie_float, get_cookie_string,
11
  Attribution, Sidebar, ExternalLinks, Hillshading, Geolocation, NPA, CDDA, Freifunk, Okapi,
12
  restoreCoordinatesFormat,
13
  document
14
*/
15
16
//var boundariesLayer = null;
17
//var boundariesLayerShown = false;
18
var map = null;
19
var theMarkers = new Markers();
20
21
var CLAT_DEFAULT = 51.163375;
22
var CLON_DEFAULT = 10.447683;
23
var ZOOM_DEFAULT = 12;
24
var MAPTYPE_DEFAULT = "OSM";
25
var RADIUS_DEFAULT = 0;
26
27
28
function enterEditMode(id) {
29
    'use strict';
30
31
    trackMarker('edit');
32
    var m = theMarkers.getById(id);
33
34
    $('#dyn' + id + ' > .markeredit .edit_name').val(m.getName());
35
    $('#edit_coordinates' + m.getAlpha()).val(Coordinates.toString(m.getPosition()));
36
    $('#edit_circle' + m.getAlpha()).val(m.getRadius());
37
38
    $('#dyn' + id + ' > .markerview').hide();
39
    $('#dyn' + id + ' > .markeredit').show();
40
}
41
42
43
function leaveEditMode(id, takenew) {
44
    'use strict';
45
46
    if (takenew) {
47
        var m = theMarkers.getById(id),
48
            name = $('#dyn' + id + ' > .markeredit .edit_name').val(),
49
            name_ok = /^([a-zA-Z0-9-_]*)$/.test(name),
50
            s_coordinates = $('#edit_coordinates' + m.getAlpha()).val(),
51
            coordinates = Coordinates.fromString(s_coordinates),
52
            s_radius = $('#edit_circle' + m.getAlpha()).val(),
53
            radius = Conversion.getInteger(s_radius, 0, 100000000000),
54
            errors = [];
55
56
        if (!name_ok) {
57
            errors.push(mytrans("sidebar.markers.error_badname").replace(/%1/, name));
58
        }
59
        if (!coordinates) {
60
            errors.push(mytrans("sidebar.markers.error_badcoordinates").replace(/%1/, s_coordinates));
61
        }
62
        if (radius === null) {
63
            errors.push(mytrans("sidebar.markers.error_badradius").replace(/%1/, s_radius));
64
        }
65
66
        if (errors.length > 0) {
67
            showAlert(mytrans("dialog.error"), errors.join("<br /><br />"));
68
        } else {
69
            m.setNamePositionRadius(name, coordinates, radius);
70
            $('#dyn' + id + ' > .markerview').show();
71
            $('#dyn' + id + ' > .markeredit').hide();
72
        }
73
    } else {
74
        $('#dyn' + id + ' > .markerview').show();
75
        $('#dyn' + id + ' > .markeredit').hide();
76
    }
77
}
78
79
80
function createMarkerDiv(id) {
81
    'use strict';
82
83
    var alpha = id2alpha(id),
84
        iconw = 33,
85
        iconh = 37,
86
        offsetx = (id % 26) * iconw,
87
        offsety = Math.floor(id / 26) * iconh;
88
89
    return "<div id=\"dyn" + id + "\">" +
90
        //"<table id=\"dynview" + id + "\" style=\"width: 100%; vertical-align: middle;\">\n" +
91
        "<table class=\"markerview\" style=\"width: 100%; vertical-align: middle;\">\n" +
92
        "    <tr>\n" +
93
        "        <td rowspan=\"3\" style=\"vertical-align: top\">\n" +
94
        "            <span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\">&nbsp;</span>\n" +
95
        "        </td>\n" +
96
        "        <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" +
97
        "        <td id=\"view_name" + alpha + "\" colspan=\"2\">marker</td>\n" +
98
        "    </tr>\n" +
99
        "    <tr>\n" +
100
        "        <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" +
101
        "        <td id=\"view_coordinates" + alpha + "\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" +
102
        "    </tr>\n" +
103
        "    <tr>\n" +
104
        "        <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" +
105
        "        <td id=\"view_circle" + alpha + "\">16100 m</td>\n" +
106
        "        <td>\n" +
107
        "            <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" +
108
        "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\"  onclick=\"enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" +
109
        "            <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"theMarkers.removeById(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>\n" +
110
        "            <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"theMarkers.goto(" + id + ")\"><i class=\"fa fa-search\"></i></button>\n" +
111
        "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"theMarkers.center(" + id + ")\"><i class=\"fa fa-crosshairs\"></i></button>\n" +
112
        "            <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"projectFromMarker(" + id + ")\"><i class=\"fa fa-location-arrow\"></i></button>\n" +
113
        "            </div>\n" +
114
        "        </td>\n" +
115
        "    </tr>\n" +
116
        "</table>\n" +
117
        "<table class=\"markeredit\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" +
118
        "    <tr>\n" +
119
        "        <td rowspan=\"4\" style=\"vertical-align: top\"><span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\">&nbsp;</span>\n" +
120
        "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-map-marker\"></i></td>\n" +
121
        "        <td><input data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"edit_name form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
122
        "    </tr>\n" +
123
        "    <tr>\n" +
124
        "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-globe\"></i></td>\n" +
125
        "        <td><input id=\"edit_coordinates" + alpha + "\" data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
126
        "    </tr>\n" +
127
        "    <tr>\n" +
128
        "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-circle-blank\"></i></td>\n" +
129
        "        <td><input id=\"edit_circle" + alpha + "\" data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
130
        "    </tr>\n" +
131
        "    <tr>\n" +
132
        "        <td colspan=\"2\" style=\"text-align: right\">\n" +
133
        "            <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"javascript: leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" +
134
        "            <button class=\"btn btn-small\" type=\"button\" onclick=\"leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" +
135
        "        </td>\n" +
136
        "    </tr>\n" +
137
        "</table>" +
138
        "</div>";
139
}
140
141
142
function newMarker(coordinates, id, radius, name) {
143
    'use strict';
144
145
    if (radius < 0) {
146
        radius = RADIUS_DEFAULT;
147
    }
148
149
    if (id < 0 || id >= theMarkers.getSize() || !theMarkers.getById(id).isFree()) {
150
        id = theMarkers.getFreeId();
151
    }
152
    if (id < 0) {
153
        showAlert(
154
            mytrans("dialog.error"),
155
            mytrans("dialog.toomanymarkers_error.content").replace(/%1/, theMarkers.getSize())
156
        );
157
        return null;
158
    }
159
160
    var alpha = id2alpha(id),
161
        marker,
162
        div,
163
        nextid;
164
165
    if (!name || name === "") {
166
        name = "marker_" + alpha;
167
    }
168
169
    marker = theMarkers.getById(id);
170
    marker.initialize(map, name, coordinates, radius);
171
    div = createMarkerDiv(id);
172
173
    nextid = theMarkers.getNextUsedId(id);
174
    if (nextid < 0) {
175
        $('#dynMarkerDiv').append(div);
176
    } else {
177
        $(div).insertBefore('#dyn' + nextid);
178
    }
179
180
    $('#dyn' + id + ' > .markeredit .edit_name').keydown(function (e) {
181
        if (e.which === 27) {
182
            leaveEditMode(id, false);
183
        } else if (e.which === 13) {
184
            leaveEditMode(id, true);
185
        }
186
    });
187
188
    $('#edit_coordinates' + alpha).keydown(function (e) {
189
        if (e.which === 27) {
190
            leaveEditMode(id, false);
191
        } else if (e.which === 13) {
192
            leaveEditMode(id, true);
193
        }
194
    });
195
196
    $('#edit_circle' + alpha).keydown(function (e) {
197
        if (e.which === 27) {
198
            leaveEditMode(id, false);
199
        } else if (e.which === 13) {
200
            leaveEditMode(id, true);
201
        }
202
    });
203
204
    $('#btnmarkers2').show();
205
    $('#btnmarkersdelete1').removeAttr('disabled');
206
    $('#btnmarkersdelete2').removeAttr('disabled');
207
208
    marker.update();
209
    theMarkers.saveMarkersList();
210
    Lines.updateLinesMarkerAdded();
211
212
    return marker;
213
}
214
215
216
function projectFromMarker(id) {
217
    'use strict';
218
219
    trackMarker('project');
220
221
    var mm = theMarkers.getById(id),
222
        oldpos = mm.getPosition();
223
224
    showProjectionDialog(
225
        function (data1, data2) {
226
            var angle = Conversion.getFloat(data1, 0, 360),
227
                dist = Conversion.getFloat(data2, 0, 100000000000),
228
                newpos,
229
                newmarker;
230
231
            if (angle === null) {
232
                showAlert(
233
                    mytrans("dialog.error"),
234
                    mytrans("dialog.projection.error_bad_bearing").replace(/%1/, data1)
235
                );
236
                return;
237
            }
238
239
            if (dist === null) {
240
                showAlert(
241
                    mytrans("dialog.error"),
242
                    mytrans("dialog.projection.error_bad_distance").replace(/%1/, data2)
243
                );
244
                return;
245
            }
246
247
            newpos = Coordinates.projection_geodesic(oldpos, angle, dist);
248
            newmarker = newMarker(newpos, -1, RADIUS_DEFAULT, null);
249
            if (newmarker) {
250
                showAlert(
251
                    mytrans("dialog.information"),
252
                    mytrans("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha())
253
                );
254
            }
255
        }
256
    );
257
}
258
259
260
function storeCenter() {
261
    'use strict';
262
263
    var c = map.getCenter();
264
    Cookies.set('clat', c.lat(), {expires: 30});
265
    Cookies.set('clon', c.lng(), {expires: 30});
266
}
267
268
269
function storeZoom() {
270
    'use strict';
271
272
    Cookies.set('zoom', map.getZoom(), {expires: 30});
273
}
274
275
276
function storeMapType() {
277
    'use strict';
278
279
    Cookies.set('maptype', map.getMapTypeId(), {expires: 30});
280
}
281
282
283
function getFeaturesString() {
284
    'use strict';
285
286
    var s = "";
287
    //if ($('#boundaries').is(':checked')) { s += "b"; }
288
    if ($('#geocaches').is(':checked')) { s += "g"; }
289
    if ($('#hillshading').is(':checked')) { s += "h"; }
290
    if ($('#npa').is(':checked')) { s += "n"; }
291
    if ($('#freifunk').is(':checked')) { s += "f"; }
292
293
    return s;
294
}
295
296
297
function getPermalink() {
298
    'use strict';
299
300
    var lat = map.getCenter().lat(),
301
        lng = map.getCenter().lng();
302
303
    return "http://flopp.net/" +
304
        "?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) +
305
        "&z=" + map.getZoom() +
306
        "&t=" + map.getMapTypeId() +
307
        "&f=" + getFeaturesString() +
308
        "&m=" + theMarkers.toString() +
309
        "&d=" + Lines.getLinesText();
310
}
311
312
function generatePermalink() {
313
    'use strict';
314
315
    var link = getPermalink();
316
    showLinkDialog(link);
317
}
318
319
320
function repairLat(x, d) {
321
    'use strict';
322
323
    if (Coordinates.validLat(x)) {
324
        return x;
325
    }
326
327
    return d;
328
}
329
330
331
function repairLon(x, d) {
332
    'use strict';
333
334
    if (Coordinates.validLng(x)) {
335
        return x;
336
    }
337
338
    return d;
339
}
340
341
342
function repairRadius(x, d) {
343
    'use strict';
344
345
    if (x === null || isNaN(x) || x < 0 || x > 100000000) {
346
        return d;
347
    }
348
349
    return x;
350
}
351
352
353
function repairZoom(x, d) {
354
    'use strict';
355
356
    if (x === null || isNaN(x) || x < 1 || x > 20) {
357
        return d;
358
    }
359
360
    return x;
361
}
362
363
364
function repairMaptype(t, d) {
365
    'use strict';
366
367
    if (t ===  "OSM" || t ===  "OSM/DE" || t ===  "OCM" || t ===  "OUTD" || t ===  "TOPO" ||
368
            t ===  "satellite" || t ===  "hybrid" || t ===  "roadmap" || t ===  "terrain") {
369
        return t;
370
    }
371
372
    return d;
373
}
374
375
376
function parseMarkersFromUrl(urlarg) {
377
    'use strict';
378
379
    if (urlarg === null) {
380
        return [];
381
    }
382
383
    var markers = [],
384
        data;
385
386
    // ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)?
387
    // COORDS=LAT:LON or DEG or DMMM
388
    if (urlarg.indexOf("*") >= 0) {
389
        data = urlarg.split('*');
390
    } else {
391
        /* sep is '|' */
392
        data = urlarg.split('|');
393
    }
394
395
    data.map(function (dataitem) {
396
        dataitem = dataitem.split(':');
397
        if (dataitem.length < 3 || dataitem.length > 5) {
398
            return;
399
        }
400
401
        var m = {
402
                alpha: dataitem[0],
403
                id: alpha2id(dataitem[0]),
404
                name: null,
405
                coords: null,
406
                r: 0
407
            },
408
            index = 1,
409
            lat,
410
            lon;
411
412
        if (m.id < 0) {
413
            return;
414
        }
415
416
        lat = parseFloat(dataitem[index]);
417
        lon = parseFloat(dataitem[index + 1]);
418
        if (Coordinates.valid(lat, lon)) {
419
            index += 2;
420
            m.coords = new google.maps.LatLng(lat, lon);
421
        } else {
422
            m.coords = Coordinates.fromString(dataitem[index]);
423
            index += 1;
424
        }
425
        if (!m.coords) {
426
            return;
427
        }
428
429
        m.r = repairRadius(parseFloat(dataitem[index]), 0);
430 View Code Duplication
        index = index + 1;
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
431
432
        if (index < dataitem.length &&
433
                /^([a-zA-Z0-9-_]*)$/.test(dataitem[index])) {
434
            m.name = dataitem[index];
435
        }
436
437
        markers.push(m);
438
    });
439
440
    return markers;
441
}
442
443
444
function parseCenterFromUrl(urlarg) {
445
    'use strict';
446
447
    if (urlarg === null) {
448
        return null;
449
    }
450
451
    var data = urlarg.split(':'),
452
        lat,
453
        lon;
454
455
    if (data.length === 1) {
456
        return Coordinates.fromString(data[0]);
457
    }
458
459
    if (data.length === 2) {
460
        lat = parseFloat(data[0]);
461
        lon = parseFloat(data[1]);
462
        if (Coordinates.valid(lat, lon)) {
463
            return new google.maps.LatLng(lat, lon);
464
        }
465
    }
466
467
    return null;
468
}
469
470
471
function parseLinesFromUrl(urlarg) {
472
    'use strict';
473
474
    if (urlarg === null) {
475
        return [];
476
    }
477
478
    var lines = [];
479
480
    /* be backwards compatible */
481
    if (urlarg.length === 3
482
            && alpha2id(urlarg[0]) >= 0
483
            && urlarg[1] === '*'
484
            && alpha2id(urlarg[1]) >= 0) {
485
        urlarg = urlarg[0] + ':' + urlarg[2];
486
    }
487
488
    urlarg.split('*').map(function (pair_string) {
489
        var m = {source: -1, target: -1},
490
            pair = pair_string.split(':');
491
492
        if (pair.length !== 2) {
493
            return;
494
        }
495
496
        m.source = alpha2id(pair[0]);
497
        m.target = alpha2id(pair[1]);
498
499
        lines.push(m);
500
    });
501
502
    return lines;
503
}
504
505
506
function parseMarkersFromCookies() {
507
    'use strict';
508
509
    var raw_ids = Cookies.get('markers'),
510
        markers = [];
511
512
    if (raw_ids === null || raw_ids === undefined) {
513
        return markers;
514
    }
515
516
    raw_ids.split(':').map(function (id_string) {
517
        var m = {id: null, name: null, coords: null, r: 0},
518
            raw_data,
519
            data,
520
            lat,
521
            lon;
522
523
        m.id = parseInt(id_string, 10);
524
        if (m.id === null || m.id < 0 || m.id >= 26 * 10) {
525
            return;
526
        }
527
528
        raw_data = Cookies.get('marker' + m.id);
529
        if (raw_data === null || raw_data === undefined) {
530
            return;
531
        }
532
533
        data = raw_data.split(':');
534
        if (data.length !== 4) {
535
            return;
536
        }
537
538
        lat = parseFloat(data[0]);
539
        lon = parseFloat(data[1]);
540
        if (!Coordinates.valid(lat, lon)) {
541
            return;
542
        }
543
        m.coords = new google.maps.LatLng(lat, lon);
544
545
        m.r = repairRadius(parseFloat(data[2]), 0);
546
547
        if (/^([a-zA-Z0-9-_]*)$/.test(data[3])) {
548
            m.name = data[3];
549
        }
550
551 View Code Duplication
        markers.push(m);
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
552
    });
553
554
    return markers;
555
}
556
557
558
function parseLinesFromCookies() {
559
    'use strict';
560
561
    var raw_lines = Cookies.get('lines'),
562
        lines = [];
563
564
    if (raw_lines === null || raw_lines === undefined) {
565
        return lines;
566
    }
567
568
    raw_lines.split('*').map(function (pair_string) {
569
        var m = {source: -1, target: -1},
570
            pair = pair_string.split(':');
571
572
        if (pair.length !== 2) {
573
            return;
574
        }
575
576
        m.source = alpha2id(pair[0]);
577
        m.target = alpha2id(pair[1]);
578
579
        lines.push(m);
580
    });
581
582
    return lines;
583
}
584
585
586
function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) {
587
    'use strict';
588
589
    var center = null,
0 ignored issues
show
Unused Code introduced by
The assignment to center seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
590
        //atDefaultCenter = false,
591
        zoom = parseInt(xzoom, 10),
592
        maptype = xmap,
593
        loadfromcookies = false,
594
        markerdata = parseMarkersFromUrl(xmarkers),
595
        markercenter = null,
596
        clat = 0,
597
        clon = 0;
598
    if (markerdata.length > 0) {
599
        markerdata.map(function (m) {
600
            clat += m.coords.lat();
601
            clon += m.coords.lng();
602
        });
603
        markercenter = new google.maps.LatLng(clat / markerdata.length, clon / markerdata.length);
604
    }
605
606
    if (xcenter && xcenter !== '') {
607
        center = parseCenterFromUrl(xcenter);
608
    } else if (markercenter) {
609
        center = markercenter;
610
    } else {
611
        loadfromcookies = true;
612
613
        /* try to read coordinats from cookie */
614
        clat = get_cookie_float('clat', CLAT_DEFAULT);
615
        clon = get_cookie_float('clon', CLON_DEFAULT);
616
        //if (clat === CLAT_DEFAULT && clon === CLON_DEFAULT) {
617
        //    atDefaultCenter = true;
618
        //}
619
620
        clat = repairLat(clat, CLAT_DEFAULT);
621
        clon = repairLon(clon, CLON_DEFAULT);
622
        center = new google.maps.LatLng(clat, clon);
623
624
        zoom = get_cookie_int('zoom', ZOOM_DEFAULT);
625
        maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT);
626
    }
627
628
    if (!center) {
629
        center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT);
630
        //atDefaultCenter = true;
631
    }
632
633
    zoom = repairZoom(zoom, ZOOM_DEFAULT);
634
    maptype = repairMaptype(maptype, MAPTYPE_DEFAULT);
635
    map = new google.maps.Map(
636
        document.getElementById("themap"),
637
        {
638
            zoom: zoom,
639
            center: center,
640
            scaleControl: true,
641
            streetViewControl: false,
642
            mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] },
643
            mapTypeId: google.maps.MapTypeId.ROADMAP
644
        }
645
    );
646
647
    map.mapTypes.set("OSM", osmProvider("OSM"));
648
    map.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE"));
649
    map.mapTypes.set("OCM", ocmProvider("OCM"));
650
    map.mapTypes.set("OUTD", thunderforestOutdoorsProvider("OUTD"));
651
    map.mapTypes.set("TOPO", opentopomapProvider("TOPO"));
652
    map.setMapTypeId(maptype);
653
654
    Attribution.init(map);
655
    Sidebar.init(map);
656
    ExternalLinks.init(map);
657
    Lines.init(map);
658
    Geolocation.init(map);
659
    Hillshading.init(map);
660
    NPA.init(map);
661
    CDDA.init(map);
662
    Freifunk.init(map);
663
    Okapi.init(map);
664
665
    //boundariesLayer = new google.maps.ImageMapType({
666
    //  getTileUrl: function(coord, zoom) {
667
    //    if (6 <= zoom && zoom <= 16)
668
    //    {
669
    //      return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom);
670
    //    }
671
    //    else
672
    //    {
673
    //      return null;
674
    //    }
675
    //  },
676
    //  tileSize: new google.maps.Size(256, 256),
677
    //  name: "adminb",
678
    //  alt: "Administrative Boundaries",
679
    //  maxZoom: 16 });
680
681
    map.setCenter(center, zoom);
682
683
    google.maps.event.addListener(map, "center_changed", function () {
684
        storeZoom();
685
        storeCenter();
686
    });
687
    google.maps.event.addListener(map, "zoom_changed", function () {
688
        storeZoom();
689
        storeCenter();
690
    });
691
    google.maps.event.addListener(map, "maptypeid_changed", function () {
692
        storeMapType();
693
    });
694
695
    if (loadfromcookies) {
696
        parseMarkersFromCookies().map(function (m) {
697
            newMarker(m.coords, m.id, m.r, m.name);
698
        });
699
700
        parseLinesFromCookies().map(function (m) {
701
            if (m.source >= 0 && theMarkers.getById(m.source).isFree()) {
702
                m.source = -1;
703
            }
704
            if (m.target >= 0 && theMarkers.getById(m.target).isFree()) {
705
                m.target = -1;
706
            }
707
            Lines.newLine(m.source, m.target);
708
        });
709
    } else {
710
        markerdata.map(function (m) {
711
            newMarker(m.coords, m.id, m.r, m.name);
712
        });
713
714
        parseLinesFromUrl(xlines).map(function (m) {
715
            if (m.source >= 0 && theMarkers.getById(m.source).isFree()) {
716
                m.source = -1;
717
            }
718
            if (m.target >= 0 && theMarkers.getById(m.target).isFree()) {
719
                m.target = -1;
720
            }
721
            Lines.newLine(m.source, m.target);
722
        });
723
    }
724
725
    Okapi.setShowCache(xgeocache);
726
    Sidebar.restore(true);
727
    xfeatures = xfeatures.toLowerCase();
728
    if (xfeatures === '[default]') {
729
        Hillshading.restore(false);
730
        //restoreBoundaries(false);
731
        Okapi.restore(false);
732
        NPA.toggle(false);
733
        CDDA.toggle(false);
734
        Freifunk.toggle(false);
735
    } else {
736
        Hillshading.toggle(xfeatures.indexOf('h') >= 0);
737
        //toggleBoundaries(xfeatures.indexOf('b') >= 0);
738
        Okapi.toggle(xfeatures.indexOf('g') >= 0);
739
        NPA.toggle(xfeatures.indexOf('n') >= 0);
740
        Freifunk.toggle(xfeatures.indexOf('f') >= 0);
741
    }
742
    restoreCoordinatesFormat("DM");
743
744
    if (xgeocache !== "") {
745
        Okapi.toggle(true);
746
        //atDefaultCenter = false;
747
    }
748
749
    Attribution.forceUpdate();
750
751
    //if (atDefaultCenter) {
752
    //  Geolocation.whereAmI();
753
    //}
754
}
755